package com.qf.leadnewscommon.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MinioPorperties.class)
@ConditionalOnProperty(name = "minio.enable",havingValue = "true")
public class MinioAutoConfiguration {

    @Autowired
    private MinioPorperties porperties;

    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(porperties.getEndpoint())
                .credentials(porperties.getUsername(), porperties.getPassword())
                .build();
    }

    @Bean
    public MinioOperator minioOperator(MinioClient minioClient){
        return new MinioOperator(minioClient,porperties);
    }


}
